

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_Modulo_RT : RT_Node
    {
        public RT_SingleValuePort Value_RT;

        public RT_SingleValuePort ModuloBy_RT;

        public RT_SingleValuePort Result_RT;

        public Node_Modulo_RT(Node_Modulo sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            Value_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.Value, this);

            ModuloBy_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.ModuloBy, this);

            Result_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Result, this);
            Result_RT.OnGetValue = GetResult;
        }

        public AValue GetResult(DAG_Executor executor)
        {
            Result_RT.SourceValue.Reset();
            if (Result_RT.SourceValue.ValueType == AValue.EValueType.Integer)
            {
                int value = Value_RT.GetValue(executor).ToInteger().Item2;
                int mod = ModuloBy_RT.GetValue(executor).ToInteger().Item2;

                int result = mod == 0 ? value : value % mod;
                Result_RT.SourceValue.SetInteger(result);
            }
            else if (Result_RT.SourceValue.ValueType == AValue.EValueType.Scalar)
            {
                float value = Value_RT.GetValue(executor).ToScalar().Item2;
                float mod = ModuloBy_RT.GetValue(executor).ToScalar().Item2;

                float result = mod == 0 ? value : value % mod;
                Result_RT.SourceValue.SetScalar(result);
            }
            return Result_RT.SourceValue;
        }


    }
}